<template>
  <div class="cataAdd">
		<!-- 表单验证 -->
    <el-form :model="cata" :rules="rules" ref="cataAdd" label-width="100px" class="demo-ruleForm">
  <el-form-item label="分类名称" prop="cataName">
    <el-input v-model="cata.name"></el-input>
  </el-form-item>
  <el-form-item label="父级分类" prop="region">

    <el-select v-model="cata.pid" placeholder="请选择父级分类">
      <el-option label="顶层分类" :value="0"></el-option>
      <el-option
      v-for="cata in allCata"
      :key="cata.id"
      :label="cata.cateName"
      :value="cata.id">

      </el-option>
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
  </el-form-item>
</el-form>
    <!-- /表单验证 -->
  </div>
</template>

<script>
export default {
  props: {
    allCata: {
      type: Array,
      required: true
    }

  },
  mounted () {
    console.log(this.allCata)
  },
  data () {
    return {
      cata: {
        cataName: '',
        pid: 0,
        usable: 1,
        icon: ''
      },
      rules: {
        cateName: [
          {
            required: true,
            // 验证不通过时，错误提示文案
            message: '当前输入框必填'
          }
        ]
      }
    }
  },
  methods: {
    submitForm () {
      this.$refs.cateAdd.validate((valid) => {
        if (valid) {
          // 验证通过
          this.$emit('addCate', this.cate)
        } else {
          // 验证不通过
          this.$message({
            type: 'error',
            message: '表单验证不通过'
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
